package hn.cch.spring.boot.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;

@RestController
public class ResponseController {

    @GetMapping(value = "/")
    public StreamingResponseBody getStreaming(HttpServletResponse response) {
        return outputStream -> {
            outputStream.write("Streaming".getBytes(StandardCharsets.UTF_8));
        };

    }

    public DeferredResult<String> getDeferredResult() {
        DeferredResult<String> deferredResult = new DeferredResult<>();
        deferredResult.onCompletion(() -> {

        });
        return deferredResult;
    }

}
